package com.kunchi.isb.service;
import com.kunchi.isb.base.dto.ISBDto;
import com.kunchi.isb.base.exception.ISBException;
import com.kunchi.isb.base.result.ISBResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * 单服务接口基础类, 用于实现除增删改查以外的业务逻辑.
 *
 * @param <T>
 * @param <D>
 * @author 王玥麟
 */
public abstract class ISBJsonParamService<T extends ISBDto, D> extends BaseISBService<T> {

    @PostMapping("/")
    public final ISBResult<D> post(@Validated @ModelAttribute T param, BindingResult bindingResult) {
        ISBResult<D> isbResult = new ISBResult<>();

        // lambada表达式, 命令回调函数执行delete抽象方法.
        this.dealService("getById", isbResult, param, bindingResult, (i, p) -> this.doService(i, p));

        return isbResult;
    }

    abstract protected ISBResult doService(ISBResult<D> isbResult, T param) throws ISBException;
}
